﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoVanHocTapData.Interface;
using CoVanHocTapData.Entities;

namespace CoVanHocTapData.Concretes
{
    public class NienKhoaRepository:INienKhoaRepository
    {
        DangKyPhuEntities entities;
        
        #region contructor
        public NienKhoaRepository()
        {
            entities = new DangKyPhuEntities();
        }
        #endregion

        #region Repository
        SinhVienRepository svRepo = new SinhVienRepository();
        #endregion

        #region INienKhoaRepository Members
        /// <summary>
        /// kiem tra nienkhoaID co nam trong dl Nien khoa ko
        /// </summary>
        /// <param name="nienkhoaID"></param>
        /// <returns></returns>
        public bool KiemTraNienKhoaID(int nienkhoaID)
        {
            var nienkhoa = from m in entities.NienKhoas
                           where m.NienKhoaID == nienkhoaID
                           select m;
            if (nienkhoa == null)
                return false;
            return true;
        }

        public NienKhoa LayNienKhoaTuMaSV(string maSV)
        {
            SinhVien sinhVien = svRepo.LaySVTuMaSV(maSV);
            return (from m in entities.NienKhoas
                    where m.NienKhoaID == sinhVien.Lop.NienKhoaID
                    select m).FirstOrDefault();
        }
        #endregion
    }
}
